package com.tanhua.server.controller;

import com.tanhua.dubbo.api.CommentsServiceApi;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.server.CommentsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {
   @Autowired
    private CommentsService commentsService;
    @GetMapping   //查看评论列表
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10")Integer pageSize,
                                   String movementId){  //ObjectId是字符串类型,在mongodb查看时必须转化为objectId才能查看
        PageResult pageResult = commentsService.findComments(movementId,page,pageSize);
        return ResponseEntity.ok(pageResult);
    }
    @PostMapping
    public ResponseEntity sendComment(@RequestBody Map<String,String> map){
        String movementId = map.get("movementId");
        String content = map.get("comment");
        commentsService.saveComment(movementId,content);
        return ResponseEntity.ok(null);
    }
}